package de.slothsoft.commons.swing;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
 * To be used with <code>AbstractSwingWorker</code>.
 */

public abstract class AbstractSwingWorkerListener implements
		PropertyChangeListener {

	@Override
	public void propertyChange(PropertyChangeEvent event) {
		String propertyName = event.getPropertyName();
		if (AbstractSwingWorker.PROPERTY_PROGRESS.equals(propertyName)) {
			progressChanged(((Integer) event.getOldValue()).intValue(),
					((Integer) event.getNewValue()).intValue());
		} else if (AbstractSwingWorker.PROPERTY_MAXIMUM.equals(propertyName)) {
			maximumChanged(((Integer) event.getOldValue()).intValue(),
					((Integer) event.getNewValue()).intValue());
		} else if (AbstractSwingWorker.PROPERTY_TASK_NAME.equals(propertyName)) {
			taskNameChanged((String) event.getOldValue(),
					(String) event.getNewValue());
		} else if (AbstractSwingWorker.PROPERTY_SUB_TASK_NAME
				.equals(propertyName)) {
			subTaskNameChanged((String) event.getOldValue(),
					(String) event.getNewValue());
		}
	}

	protected abstract void progressChanged(int oldValue, int newValue);

	protected abstract void maximumChanged(int oldValue, int newValue);

	protected abstract void taskNameChanged(String oldValue, String newValue);

	protected abstract void subTaskNameChanged(String oldValue, String newValue);
}
